<template>
  <el-dialog
    title="移动资产"
    :visible.sync="dialogVisible"
    width="50%">

    <cs-tree
      :treeData="treeData"
      @handleNodeClick="handleNodeClick"
      ref="tree"/>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="addMove">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  moveAssets
} from '@/api/assets/group.js'
import CsTree from '@/components/cs-tree'
export default {
  data() {
    return {
      dialogVisible: false,
      treeData: [],
      id: '',
      ids: []
    }
  },
  components: {
    CsTree
  },
  methods: {
    init(data, ids, flag) {
      this.ids = ids
      this.treeData = data
      this.dialogVisible = flag
    },
    handleNodeClick(val) {
      this.id = val.id
    },
    // 提交资产的移动
    addMove() {
      const data = {
        assersIds: this.ids,
        groupId: this.id
      }
      if (!this.id) {
        this.$message.error('请选择资产组！')
      } else {
        moveAssets(data).then((res) => {
          this.dialogVisible = false
          this.$emit('assetsRemove')
        })
      }
    }
  }
}
</script>

<style>
</style>
